package com.zyx.yygh.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zyx.yygh.common.result.Result;
import com.zyx.yygh.model.user.UserInfo;
import com.zyx.yygh.user.service.UserInfoService;
import com.zyx.yygh.vo.user.UserInfoQueryVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author zyx
 * @version 1.0
 * @date 2022/1/23 023 11:16
 */
@RestController
@RequestMapping("/admin/user")
public class UserController {

    @Resource
    private UserInfoService userInfoService;

    /**
     * 用户列表
     *
     * @param page
     * @param limit
     * @param userInfoQueryVo
     * @return
     */
    @GetMapping("{page}/{limit}")
    public Result list(@PathVariable long page,
                       @PathVariable long limit,
                       UserInfoQueryVo userInfoQueryVo) {

        Page<UserInfo> userInfoPage = new Page<>(page, limit);
        IPage<UserInfo> pageModel =
                userInfoService.selectPage(userInfoPage, userInfoQueryVo);
        return Result.ok(pageModel);
    }

    /**
     * 用户锁定
     */
    @GetMapping("lock/{userId}/{status}")
    public Result lock(@PathVariable Long userId, @PathVariable Integer status) {

        userInfoService.lock(userId, status);
        return Result.ok();
    }

    /**
     * 用户详情
     */
    @GetMapping("show/{userId}")
    public Result show(@PathVariable Long userId) {

        Map<String,Object> map = userInfoService.show(userId);
        return Result.ok(map);
    }

    /**
     * 认证审批
     */
    @GetMapping("approval/{userId}/{authStatus}")
    public Result approval(@PathVariable Long userId, @PathVariable Integer authStatus){

        userInfoService.aproval(userId,authStatus);
        return Result.ok();
    }

}
